package cn.botter.auth.domain.service.impl;

import cn.botter.auth.common.enums.IsDeletedEnum;
import cn.botter.auth.domain.entity.AuthRolePermissionBO;
import cn.botter.auth.domain.service.AuthRolePermissionDomainService;
import cn.botter.auth.infra.basic.entity.AuthRolePermission;
import cn.botter.auth.infra.basic.service.AuthRolePermissionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @BelongsProject: bo-club
 * @BelongsPackage: cn.botter.auth.domain.service.impl
 * @Author: 爱写Bug的Botter
 * @CreateTime: 2025-03-17:08:28
 * @Description: 描述
 * @Version: 1.0
 */
@Service
@Slf4j
public class AuthRolePermissionDomainServiceImpl implements AuthRolePermissionDomainService {
    @Resource
    private AuthRolePermissionService authRolePermissionService;

    @Override
    public Boolean add(AuthRolePermissionBO authRolePermissionBO) {

//        AuthRolePermission authRolePermission = AuthRolePermissionConvert.INSTANCE.convertAuthPermissionBotoAuthPermission(authRolePermissionBO);
        /**
         * 批量插入数据
         */
        List<AuthRolePermission> authRolePermissionList = new ArrayList<>();
        authRolePermissionBO.getPermissionIdList().forEach(permissionId -> {
            AuthRolePermission authRolePermission = new AuthRolePermission();
            authRolePermission.setRoleId(authRolePermissionBO.getRoleId());
            authRolePermission.setPermissionId(permissionId.intValue());
            authRolePermission.setIsDeleted(IsDeletedEnum.UN_DELETED.getCode());
            authRolePermissionList.add(authRolePermission);

        });
        Integer res = authRolePermissionService.insertBatch(authRolePermissionList);
        return res > 0;
    }
}
